*     *****************************************************************   *;
*     *****************************************************************   *; 
*   Date:          December 27, 2021                               	      *;
*   Authors:       Lisa Dellmuth and Jonas Tallberg				          *;  
*   Purpose: 	   Analyses for book Legitimacy Politics: Elite  		  *;
*    Communication and Public Opinion in Global Governance (CUP, 2023)    *;
*     ****************************************************************    *;
*     ****************************************************************    *;


*Chapter 5
*********************************


set scheme plotplain


*Differences in pre-treatment beliefs

tab Q9a, nol
tab Q9b
tab Q10a, nol 
tab Q10b
rename Q9a uneffdem
rename Q9b natoeffdem
rename Q10a defense
rename Q10b moral
recode uneffdem 977=.
recode natoeffdem 977=.
recode defense 977=.
recode moral 977=.
tab Q7, nol
gen dem1vsrep=.
replace dem1vsrep=0 if Q7==2
replace dem1vsrep=1 if Q7==1
gen dem1vsind=.
replace dem1vsind=0 if Q7==977
replace dem1vsind=1 if Q7==1

ttest uneffdem, by(dem1vsrep)
ttest natoeffdem, by(dem1vsrep)
ttest uneffdem, by(dem1vsind)
ttest natoeffdem, by(dem1vsind)

ttest defense, by(dem1vsrep)
ttest moral, by(dem1vsrep)
ttest defense, by(dem1vsind)
ttest moral, by(dem1vsind)

tab Q7, nol
gen partisanid=Q7
recode partisanid 977=. 
gen dem=.
replace dem=0 if partisanid~=1
replace dem=1 if partisanid==1
gen rep=.
replace rep=0 if partisanid~=2
replace rep=1 if partisanid==2 

tab Q7, nol
gen partyid_y=0
replace partyid_y=1 if Q7~=977 

tab Q8
gen partisanstr=Q8
recode partisanstr 977=. 4=0 3=1 1=3
tab partisanstr

* Comprehension checks - for UN and NATO

tab Group, gen(group)
*NATO
tab Q12
tab Q13
tab Q14
ttest Q14, by(group4)

*UN
tab Q16
tab Q17
ttest Q18, by(group4)
tab Q18

tab Group, gen(group)

*Group 4 high polarization - We also found no significant difference in recall accuracy based on whether the respondent was in a polarized or non-polarized condition
ttest Q12, by(group4)
ttest Q13, by(group4) 
ttest Q16, by(group4)
ttest Q17, by(group4) 




use partycues_de.dta, clear
tab Q9a, nol
tab Q9b
tab Q10a, nol 
tab Q10b
rename Q9a uneffdem
rename Q9b natoeffdem
rename Q10a defense
rename Q10b moral
recode uneffdem 977=.
recode natoeffdem 977=.
recode defense 977=.
recode moral 977=.
tab Q7
tab Q7, nol
gen spd1vscducsu=.
replace spd1vscducsu=0 if Q7==1
replace spd1vscducsu=1 if Q7==2
gen spd1vsind=.
replace spd1vsind=0 if Q7==977
replace spd1vsind=1 if Q7==2
gen spd1vsotherpartisans=.
replace spd1vsotherpartisans=0 if Q7==1|Q7==3|Q7==4|Q7==5|Q7==6|Q7==7|Q7==8
replace spd1vsotherpartisans=1 if Q7==2

ttest uneffdem, by(spd1vscducsu)
ttest natoeffdem, by(spd1vscducsu)
ttest uneffdem, by(spd1vsind)
ttest natoeffdem, by(spd1vsind)
ttest uneffdem, by(spd1vsotherpartisans)
ttest natoeffdem, by(spd1vsotherpartisans)

ttest defense, by(spd1vscducsu)
ttest moral, by(spd1vscducsu)
ttest defense, by(spd1vsotherpartisans)
ttest moral, by(spd1vsotherpartisans)
ttest defense, by(spd1vsind)
ttest moral, by(spd1vsind)

gen nato_effdem_d=.
replace nato_effdem_d=0 if nato_effdem<6
replace nato_effdem_d=1 if nato_effdem>=6

gen un_effdem_d=.
replace un_effdem_d=0 if un_effdem<6
replace un_effdem_d=1 if un_effdem>=6


*Fig 5.1
use partycues_us.dta, clear
tab Q7
gen no=1
catplot no Q7 [aweight=weight], percent vertical ytitle(Percent) title(US)

use partycues_de.dta, clear

tab Q7
gen no=1
catplot no Q7 [aweight=weight], percent vertical ytitle(Percent) title(Germany)

graph combine Fig5.1.us.gph Fig5.1.de.gph, ycommon


*Fig 5.2
use partycues_us.dta, clear
tab Q8, nol
rename Q8 ps
recode ps 977=.
gen no=1
catplot no ps [aweight=weight], percent vertical ytitle(Percent) title(US)

use partycues_de.dta, clear

rename Q8 ps
recode ps 977=.
gen no=1
catplot no ps [aweight=weight], percent vertical ytitle(Percent) title(Germany)

graph combine Fig5.2.us.gph Fig5.2.de.gph, ycommon



*Fig 5.3
use partycues_us.dta, clear
tab Q9a, nol
tab Q9b
tab Q10a, nol 
tab Q10b
rename Q9a uneffdem
rename Q9b natoeffdem
rename Q10a defense
rename Q10b moral
recode uneffdem 977=.
recode natoeffdem 977=.
recode defense 977=.
recode moral 977=.

gen no=1
graph hbar uneffdem natoeffdem moral defense [aweight=weight], ytitle(Mean score) title(US) ///
showyvars yvaroptions(relabel(1 "UN works effectively and democratically" ///
2 "NATO works effectively and democratically" ///
3 "Accepting refugees is a moral obligation for the US" ///
4 "Prioritize defense spending to ensure national security")) ///
legend(off) exclude0 ysc(r(1,11)) yla(1(1)11)

use partycues_de.dta, clear
tab Q9a, nol
tab Q9b
tab Q10a, nol 
tab Q10b
rename Q9a uneffdem
rename Q9b natoeffdem
rename Q10a defense
rename Q10b moral
recode uneffdem 977=.
recode natoeffdem 977=.
recode defense 977=.
recode moral 977=.

gen no=1
graph hbar uneffdem natoeffdem moral defense [aweight=weight], ytitle(Mean score) title(Germany) ///
showyvars yvaroptions(relabel(1 "UN works effectively and democratically" ///
2 "NATO works effectively and democratically" ///
3 "Accepting refugees is a moral obligation for Germany" ///
4 "Prioritize defense spending to ensure national security")) ///
legend(off) exclude0 ysc(r(1,11)) yla(1(1)11)

graph combine Fig5.3.us.gph Fig5.3.de.gph, ycommon col(1)





*Fig 5.4

use partycues_us.dta, clear
tab Q9a, nol
tab Q9b
tab Q10a, nol 
tab Q10b
rename Q9a uneffdem
rename Q9b natoeffdem
rename Q10a defense
rename Q10b moral
recode uneffdem 977=.
recode natoeffdem 977=.
recode defense 977=.
recode moral 977=.

gen no=1

graph hbar uneffdem natoeffdem moral defense [aweight=weight], ytitle(Mean score) ///
showyvars yvaroptions(relabel(1 "UN works effectively and democratically" ///
2 "NATO works effectively and democratically" ///
3 "Accepting refugees is a moral obligation for the US" ///
4 "Prioritize defense spending to ensure national security") ) ///
exclude0 ysc(r(1,11)) yla(1(1)11) by(Q7, legend(off) col(1))  




*Experimental analysis US
***************************

use partycues_us.dta, clear

svyset RecordNo [iweight=weight]

tab Group // control group == 5
gen cg=0
replace cg=1 if Group==5
tab cg  
gen t1=.
replace t1=0 if cg==1
replace t1=1 if group1==1
gen t2=.
replace t2=0 if cg==1
replace t2=1 if group2==1
gen t3=.
replace t3=0 if cg==1
replace t3=1 if group3==1
gen t4=.
replace t4=0 if cg==1
replace t4=1 if group4==1
tab t1
tab t2
tab t3
tab t4
tab Q7

svyset

*H1


svy:reg confnato t2_dem
svy:reg confnato t3_dem
svy:reg confnato t4_dem  
svy:reg confnato t2_rep
svy:reg confnato t3_rep
svy:reg confnato t4_rep

svy:reg confuno t2_dem
svy:reg confuno t3_dem
svy:reg confuno t4_dem 
svy:reg confuno t2_rep
svy:reg confuno t3_rep
svy:reg confuno t4_rep

*support for H1

*check for independents:
gen ind=0
replace ind=1 if Q7==977
gen t2_ind=.
replace t2_ind=0 if ind==1&cg==1
replace t2_ind=1 if ind==1&t2==1 //compares ind in T1 toind in CG
gen t3_ind=.
replace t3_ind=0 if ind==1&cg==1
replace t3_ind=1 if ind==1&t3==1 //compares ind in T1 to ind in CG
gen t4_ind=.
replace t4_ind=0 if ind==1&cg==1
replace t4_ind=1 if ind==1&t4==1 //compares ind in T1 to ind in CG

svy:reg confnato t2_ind
svy:reg confnato t3_ind
svy:reg confnato t4_ind
svy:reg confuno t2_ind
svy:reg confuno t3_ind
svy:reg confuno t4_ind


*H2 - Table 5.5

tab Q8
tab partystr  
label define close 0 "Not at all close" 1 "Not close" 2 "Quite close" 3 "Very close", modify
label values partystr close
tab partystr

svy:reg confnato t2_dem#partystr
svy:reg confnato t3_dem#partystr
svy:reg confnato t4_dem#partystr 
svy:reg confnato t2_rep#partystr
svy:reg confnato t3_rep#partystr
svy:reg confnato t4_rep#partystr

svy:reg confuno t2_dem#partystr
svy:reg confuno t3_dem#partystr
svy:reg confuno t4_dem#partystr 
svy:reg confuno t2_rep#partystr
svy:reg confuno t3_rep#partystr
svy:reg confuno t4_rep#partystr



*H3  -Issue polarization effect

*For democrats
*Compare regression coefficients of two independent samples (does it have a larger
*effect to go from t4 treatment to no treatment than from no treatment to
* t3 treatment?)

*t_obs=(b1-b2)/sqrt(se(b1)^2+se(b2)^2)​

*NATO
svy:reg confnato t3_dem
svy:reg confnato t4_dem  

*Here, b1=t4 effect and b2=t3 effect, so hypothesis is abs(b1)>b2.  
*For t4>t3
display (-.709+.974)
display (-.709+.974)/sqrt(.249^2+0.268^2) 
*b3==.265 and t=.724, df=n-1=317
*The p-value, two-tailed, is .469, one-tailed .235

*UN
svy:reg confuno t3_dem
svy:reg confuno t4_dem  

*Here, b1=t4 effect and b2=t3 effect, so hypothesis is abs(b1)>b2.  
*For t4>t3
display (.533-0.633)
display (.533-0.633)/sqrt(.249^2+0.262^2) 
*b3==-.100 and t=.277, df=n-1=331
*The p-value is, two-tailed, .782, one-tailed .391




*For republicans 
*Compare regression coefficients of two independent samples (does it have a larger
*effect to go from t4 treatment to no treatment than from no treatment to
* t3 treatment?)

*t_obs=(b1-b2)/sqrt(se(b1)^2+se(b2)^2)​

*NATO
svy:reg confnato t3_rep
svy:reg confnato t4_rep 

*Here, b1=t4 effect and b2=t3 effect, so hypothesis is abs(b1)>b2.  
*For t4>t3
display (-.628-.245)
display (-.628-.245)/sqrt(.317^2+.328^2) 
*b3==-.873 and t=-1.914, df=n-1=288
*The p-value is .056, two-tailed; .028 one-tailed 

*UN
svy:reg confuno t3_rep
svy:reg confuno t4_rep 

*Here, b1=t4 effect and b2=t3 effect, so hypothesis is abs(b1)>b2.  
*For t4>t3
display (-.437+.001)
display (-.437+.001)/sqrt(.348^2+.331^2) 
*b3==-.436 and t=-.908, df=n-1=297
*The p-value is .365, two-tailed; .182 one-tailed 





******Experimental analysis Germany

use partycues_de.dta, clear

*H1

svy:reg confnato t2_spd
svy:reg confnato t3_spd
svy:reg confnato t4_spd  
svy:reg confnato t2_cdu
svy:reg confnato t3_cdu
svy:reg confnato t4_cdu

svy:reg confuno t2_spd
svy:reg confuno t3_spd
svy:reg confuno t4_spd 
svy:reg confuno t2_cdu
svy:reg confuno t3_cdu
svy:reg confuno t4_cdu



*check for independents:
gen ind=0
replace ind=1 if Q7==977
gen t2_ind=.
replace t2_ind=0 if ind==1&cg==1
replace t2_ind=1 if ind==1&t2==1 //compares ind in T1 toind in CG
gen t3_ind=.
replace t3_ind=0 if ind==1&cg==1
replace t3_ind=1 if ind==1&t3==1 //compares ind in T1 to ind in CG
gen t4_ind=.
replace t4_ind=0 if ind==1&cg==1
replace t4_ind=1 if ind==1&t4==1 //compares ind in T1 to ind in CG

svy:reg confnato t2_ind
svy:reg confnato t3_ind
svy:reg confnato t4_ind
svy:reg confuno t2_ind
svy:reg confuno t3_ind
svy:reg confuno t4_ind



*H2

tab Q8, nol
gen partystr = Q8
recode partystr 977=. 1=3 3=1 4=0
label define close 0 "Not at all close" 1 "Not close" 2 "Quite close" 3 "Very close", modify
label values partystr close
tab partystr

svy:reg confnato t2_spd#partystr
svy:reg confnato t3_spd#partystr
svy:reg confnato t4_spd#partystr 
svy:reg confnato t2_cdu#partystr
svy:reg confnato t3_cdu#partystr
svy:reg confnato t4_cdu#partystr

svy:reg confuno t2_spd#partystr
svy:reg confuno t3_spd#partystr
svy:reg confuno t4_spd#partystr 
svy:reg confuno t2_cdu#partystr
svy:reg confuno t3_cdu#partystr
svy:reg confuno t4_cdu#partystr



*Figure 5.5

use partycues_us.dta, clear

*preserve 
*reg confnato t1_dem [aw=weight] 
*parmest, label norestore escal(N) saving(nato_t1_democrat.dta, replace)
*list parm estimate stderr dof min95 max95, clean noobs

preserve 
reg confnato t2_dem [aw=weight] 
parmest, label norestore escal(N) saving(nato_t2_democrat.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs

preserve 
reg confnato t3_dem [aw=weight] 
parmest, label norestore escal(N) saving(nato_t3_democrat.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs

preserve
reg confnato t4_dem [aw=weight] 
parmest, label norestore escal(N) saving(nato_t4_democrat.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
 
/*preserve 
reg confuno t1_dem [aw=weight] 
parmest, label norestore escal(N) saving(un_t1_democrat.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
gen str io = "UN"
sort parm io
save un_t1_democrat.dta, replace*/

preserve 
reg confuno t2_dem [aw=weight] 
parmest, label norestore escal(N) saving(un_t2_democrat.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
gen str io = "UN"
sort parm io
save un_t2_democrat.dta, replace

preserve 
reg confuno t3_dem [aw=weight] 
parmest, label norestore escal(N) saving(un_t3_democrat.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
gen str io = "UN"
sort parm io
save un_t3_democrat.dta, replace

preserve
reg confuno t4_dem [aw=weight] 
parmest, label norestore escal(N) saving(un_t4_democrat.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
gen str io = "UN"
sort parm io
save un_t4_democrat.dta, replace

*use nato_t1_democrat.dta, clear
*merge 1:1 parm using nato_t2_democrat.dta
*drop _merge
use nato_t2_democrat.dta, clear
merge 1:1 parm using nato_t3_democrat.dta
drop _merge
merge 1:1 parm using nato_t4_democrat.dta
drop _merge
gen str io = "NATO"
sort parm io
*merge 1:1 parm io  using un_t1_democrat.dta
*drop _merge
merge 1:1 parm io  using un_t2_democrat.dta
drop _merge
merge 1:1 parm io  using un_t3_democrat.dta
drop _merge
merge 1:1 parm io using un_t4_democrat.dta
drop _merge
ed
saveold fig_7_6_dem.dta, replace

use partycues_us.dta, clear

 
preserve 
reg confnato t2_rep [aw=weight] 
parmest, label norestore escal(N) saving(nato_t2_rep.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs

preserve 
reg confnato t3_rep [aw=weight] 
parmest, label norestore escal(N) saving(nato_t3_rep.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs

preserve
reg confnato t4_rep [aw=weight] 
parmest, label norestore escal(N) saving(nato_t4_rep.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
 
 
preserve 
reg confuno t2_rep [aw=weight] 
parmest, label norestore escal(N) saving(un_t2_rep.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
gen str io = "UN"
sort parm io
save un_t2_rep.dta, replace

preserve 
reg confuno t3_rep [aw=weight] 
parmest, label norestore escal(N) saving(un_t3_rep.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
gen str io = "UN"
sort parm io
save un_t3_rep.dta, replace

preserve
reg confuno t4_rep [aw=weight] 
parmest, label norestore escal(N) saving(un_t4_rep.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
gen str io = "UN"
sort parm io
save un_t4_rep.dta, replace

use nato_t2_rep.dta, clear
merge 1:1 parm using nato_t3_rep.dta
drop _merge
merge 1:1 parm using nato_t4_rep.dta
drop _merge
gen str io = "NATO"
sort parm io
*merge 1:1 parm io  using un_t1_rep.dta
*drop _merge
merge 1:1 parm io  using un_t2_rep.dta
drop _merge
merge 1:1 parm io  using un_t3_rep.dta
drop _merge
merge 1:1 parm io using un_t4_rep.dta
drop _merge
ed
saveold fig_7_6_rep.dta, replace

merge 1:1 parm io using fig_7_6_dem.dta
drop _m
saveold fig_7_6.dta, replace

sort io p
ed
drop if parm=="_cons"
drop label

*manually create rep/dem dummy, IO dummy, and treatment group variable
gen str demrep="" 
sort parm
gen treatmentgroup =.
ed parm demrep io treatmentgroup

encode demrep, gen(demrepnum)
encode io, gen(ionum)
encode parm, gen(treatment)

label define treat 1 "Party cues" 2 "Party cues, lo-po" 3 "Party cues, hi-po", modify
label values treatmentgroup treat

saveold fig_7_5.dta, replace


use fig_7_5.dta, clear
	
rename min95 yl
rename max95 yu
rename estimate ate
			
local varname ate
local group1 treatment
local group2 io
sort `group1' `group2'

gen x = _n
replace x = _n + 1 if _n > 3
replace x = _n + 2 if _n > 4
replace x = _n + 3 if _n > 6 
replace x = _n + 4 if _n > 11
replace x = _n + 5 if _n > 16

separate ate, by(io)
separate yu, by(io)
separate yl, by(io)

twoway (scatter ate1 x , msymbol(S) msize(medium) mcolor(black)) ///
       (rcap yu1 yl1 x, lcolor(black))  ///
       (scatter ate2 x , msymbol(Oh) msize(large) mcolor(black)) ///
       (rcap yu2 yl2 x, lcolor(black) ), scheme(lean1)  ///
	   xlabel(none) xtitle(" ", size(3)) b2("Treatment groups compared to control group") ///
	   ytitle(Average treatment effect, size(3)) yscale(r(-1(.5)1)) ///
	   text(-1.4 0.7 "Party cues, Democrats", place(e) size(2.5)) ///
	   text(-1.4 3.5 "Party cues, Republican", place(e) size(2.5)) ///
	   text(-1.4 6.5 "Low pol., Democrats", place(e) size(2.5)) ///
	   text(-1.4 9 "Low pol., Republican", place(e) size(2.5)) ///
	   text(-1.4 12 "High pol., Democrats", place(e) size(2.5)) ///
	   text(-1.4 15 "High pol., Republican", place(e) size(2.5)) ///
	   legend(order(1 "NATO" 3 "UN") position(1) row(1) ring(0)) ///
	   name(fig4, replace) graphregion(color(white)) ylab(, labsize(2.5) nogrid) ///
	   yline(0, lcolor(black) lpattern(dash))




* Figure 5.6
	   

use partycues_de.dta, clear

preserve 
reg confnato t2_spd [aw=weight] 
parmest, label norestore escal(N) saving(nato_t2_spd_de.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs

preserve 
reg confnato t3_spd [aw=weight] 
parmest, label norestore escal(N) saving(nato_t3_spd_de.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs

preserve
reg confnato t4_spd [aw=weight] 
parmest, label norestore escal(N) saving(nato_t4_spd_de.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs

preserve 
reg confuno t2_spd [aw=weight] 
parmest, label norestore escal(N) saving(un_t2_spd_de.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
gen str io = "UN"
sort parm io
save un_t2_spd_de.dta, replace

preserve 
reg confuno t3_spd [aw=weight] 
parmest, label norestore escal(N) saving(un_t3_spd_de.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
gen str io = "UN"
sort parm io
save un_t3_spd_de.dta, replace

preserve
reg confuno t4_spd [aw=weight] 
parmest, label norestore escal(N) saving(un_t4_spd_de.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
gen str io = "UN"
sort parm io
save un_t4_spd_de.dta, replace

*use nato_t1_spd_de.dta, clear
*merge 1:1 parm using nato_t2_spd_de.dta
*drop _merge
use nato_t2_spd_de.dta, clear
merge 1:1 parm using nato_t3_spd_de.dta
drop _merge
merge 1:1 parm using nato_t4_spd_de.dta
drop _merge
gen str io = "NATO"
sort parm io
*merge 1:1 parm io  using un_t1_spd_de.dta
*drop _merge
merge 1:1 parm io  using un_t2_spd_de.dta
drop _merge
merge 1:1 parm io  using un_t3_spd_de.dta
drop _merge
merge 1:1 parm io using un_t4_spd_de.dta
drop _merge
ed
saveold fig_7_6_spd_de.dta, replace

use partycues_de.dta, clear

preserve 
reg confnato t2_cdu [aw=weight] 
parmest, label norestore escal(N) saving(nato_t2_cdu_de.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs

preserve 
reg confnato t3_cdu [aw=weight] 
parmest, label norestore escal(N) saving(nato_t3_cdu_de.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs

preserve
reg confnato t4_cdu [aw=weight] 
parmest, label norestore escal(N) saving(nato_t4_cdu_de.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs


preserve 
reg confuno t2_cdu [aw=weight] 
parmest, label norestore escal(N) saving(un_t2_cdu_de.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
gen str io = "UN"
sort parm io
save un_t2_cdu_de.dta, replace

preserve 
reg confuno t3_cdu [aw=weight] 
parmest, label norestore escal(N) saving(un_t3_cdu_de.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
gen str io = "UN"
sort parm io
save un_t3_cdu_de.dta, replace

preserve
reg confuno t4_cdu [aw=weight] 
parmest, label norestore escal(N) saving(un_t4_cdu_de.dta, replace)
list parm estimate stderr dof min95 max95, clean noobs
gen str io = "UN"
sort parm io
save un_t4_cdu_de.dta, replace

use nato_t2_cdu_de.dta, clear
merge 1:1 parm using nato_t3_cdu_de.dta
drop _merge
merge 1:1 parm using nato_t4_cdu_de.dta
drop _merge
gen str io = "NATO"
sort parm io
*merge 1:1 parm io  using un_t1_cdu_de.dta
*drop _merge
merge 1:1 parm io  using un_t2_cdu_de.dta
drop _merge
merge 1:1 parm io  using un_t3_cdu_de.dta
drop _merge
merge 1:1 parm io using un_t4_cdu_de.dta
drop _merge
ed
saveold fig_7_6_cdu_de.dta, replace

merge 1:1 parm io using fig_7_6_spd_de.dta
drop _m
saveold fig_7_6_de.dta, replace 

sort io p
ed
drop if parm=="_cons"
drop label

*manually create rep/dem dummy, IO dummy, and treatment group variable
gen str demrep="" 
sort parm
gen treatmentgroup =.
ed parm demrep io treatmentgroup

encode demrep, gen(demrepnum)
encode io, gen(ionum)
encode parm, gen(treatment)

label define treat 1 "Party cues" 2 "Party cues, lo-po" 3 "Party cues, hi-po", modify
label values treatmentgroup treat

saveold fig_7_6_de.dta, replace



use fig_7_6_de.dta, clear
	
rename min95 yl
rename max95 yu
rename estimate ate
			
local varname ate
local group1 treatment
local group2 io
sort `group1' `group2'

gen x = _n
replace x = _n + 1 if _n > 3
replace x = _n + 2 if _n > 4
replace x = _n + 3 if _n > 6 
replace x = _n + 4 if _n > 11
replace x = _n + 5 if _n > 16

separate ate, by(io)
separate yu, by(io)
separate yl, by(io)
ed

twoway (scatter ate1 x , msymbol(S) msize(medium) mcolor(black)) ///
       (rcap yu1 yl1 x, lcolor(black))  ///
       (scatter ate2 x , msymbol(Oh) msize(large) mcolor(black)) ///
       (rcap yu2 yl2 x, lcolor(black) ), scheme(lean1)  ///
	   xlabel(none) xtitle(" ", size(3)) b2("Treatment groups compared to control group") ///
	   ytitle(Average treatment effect, size(3)) yscale(r(-1(.5)1)) ///
	   text(-2.2 0.7 "Party cues, CDU/CSU", place(e) size(2.5)) ///
	   text(-2.2 3.5 "Party cues, SPD", place(e) size(2.5)) ///
	   text(-2.2 6.5 "Low pol., CDU/CSU", place(e) size(2.5)) ///
	   text(-2.2 9 "Low pol., SPD", place(e) size(2.5)) ///
	   text(-2.2 12 "High pol., CDU/CSU", place(e) size(2.5)) ///
	   text(-2.2 15 "High pol., SPD", place(e) size(2.5)) ///
	   legend(order(1 "NATO" 3 "UN") position(1) row(1) ring(3)) ///
	   name(fig4, replace) graphregion(color(white)) ylab(, labsize(2.5) nogrid) ///
	   yline(0, lcolor(black) lpattern(dash))
